﻿/// <reference path="/Js/jsUtil.js"/> 
/// <reference path="/Js/main.js"/> 
/// <reference path="/Js/ext-5.0.0-gpl/build/ext-all.js"/> 
/// <reference path="/Js/app.js"/> 
/**
* 
*/
Ext.require('Region.Js.Region_Module');
Ext.define("RBAC.Js.Users_Address_List", {
    constructor: function (config) {
        this.initConfig(config);
    },
    renderList: function (view) {
        var Store = Ext.create('Ext.data.Store', { //store和model一起创建
            //storeId: 'simpsonsStore',
            fields: ['UserId'],
            pageSize: 30,
            autoLoad: true,
            proxy: {
                type: 'ajax',
                enablePaging: true,//支持翻页
                url: '/RBAC/Services/RBAC_Users.asmx/GetLists',
                pageParam: 'page',
                startParam: '{startParam}',
                limitParam: 'rows',
                headers: { "Content-Type": 'application/json' },
                reader: {
                    type: 'json',
                    rootProperty: 'd.Table.rows',
                    totalProperty: 'd.Total'
                },
                writer: {
                    type: 'json'
                },
                extraParams: $.par2Json($("form[name=fmList]", view.dom).serialize()),
                sortParam: 'LastTime'
            }
        });
        var Columns = easyui2extgrid([[
                    { field: 'UserId', title: '编号', width: 40 },
                    { field: 'UserName', title: '姓名', width: X_WIDTH.UserName, align: 'center' },
                    { field: 'UserSex', title: '性别', width: X_WIDTH.Sex, align: 'center', formatter: formatSex },
                    { field: 'UserState', title: '状态', width: 50, align: 'center', formatter: function (v, r, k) { return X_USERSTATE[v]; } },
                    { field: 'UserMobile', title: '电话', width: X_WIDTH.Tel, align: 'center', formatter: function (v, r, k) { return v; } },
                    { field: 'LastLoginTime', title: '最后登陆', width: X_WIDTH.Time, align: 'center', formatter: formatShortTime },
                    { field: 'LastLoginIp', title: '最后IP', width: X_WIDTH.Ip, align: 'center', formatter: function (v, r, k) { return v; } },
                    { field: 'UserOnline', title: '在线', width: 50, formatter: function (v, r, k) { return X_ONLINESTATE[v]; }, align: 'center' },
                    { field: 'DepartId', title: '部门', width: X_WIDTH.Depart, align: 'center', formatter: formatDepart },
                    { field: 'PostId', title: '职位', width: X_WIDTH.Depart, align: 'center', formatter: formatPost }
                ]]);
        var selectRowData = {};
        var tbl = view.query(".mainList");
        var grid = Ext.create('Ext.grid.Panel', {
            scroll: true, height: deskExt.getHeight() - $(".auto", tbl.dom).height() - X_TAB_HEIGHT,
            store: Store, width: '100%', forceFit: true,
            columns: Columns,
            bbar: Ext.create('Ext.PagingToolbar', {
                store: Store,
                displayInfo: true,
                displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
                emptyMsg: "没有数据"
            }),
            renderTo: tbl
        });

        //events
        $("form[name=fmList]", view.dom).submit(function () {
            grid.store.proxy.extraParams = $.par2Json($("form[name=fmList]", view.dom).serialize());
            grid.store.loadPage(1);
            grid.store.reload();
            return false;
        });
    }
});
//(function a(n) {
//    //按钮链接
//    var $btnSearch = $("input[name=btnSearch]","#"+n);
//    //搜索项
//    var $txtUserName = $("input[name=txtUserName]","#"+n);
//    //表
//    var $dg = $("table[name=dg]","#"+n);
//    //枚举
//    var enumUrl = {//s服务 w//窗体
//        sList: 'RBAC/Services/RBAC_Users.asmx/GetLists'
//    };
//    //事件
//    $btnSearch.click(function () { render(); });
   
//    render();
//    //函数
//    function render() {
//        var param = { txtUserName: $txtUserName.val() };
//        $dg.datagrid({
//            url: enumUrl.sList + "?" + $("form[name=fmUserList]","#"+n).serialize(),
//            //title: '用户列表',
//            method: 'GET',
//            idFiled: 'UserId',
//            loadMsg: '正在加载，请稍候……',
//            pagination: true,
//            rownumbers: true,
//            pageNumber: 1, headers: { 'Content-Type': 'application/json;utf-8' },
//            pageSize: 20,
//            toolbar: $("div[name=toolbar]","#"+n),
//            singleSelect: true,
//            columns: [[
//                    { field: 'UserId', title: '编号', width: 40 },
//                    { field: 'UserName', title: '姓名', width: X_WIDTH.UserName, align: 'center' },
//                    { field: 'UserSex', title: '性别', width: X_WIDTH.Sex, align: 'center', formatter: formatSex },
//                    { field: 'UserState', title: '状态', width: 50, align: 'center', formatter: function (v, r, k) { return X_USERSTATE[v]; } },
//                    { field: 'UserMobile', title: '电话', width: X_WIDTH.Tel, align: 'center', formatter: function (v, r, k) { return v; } },
//                    { field: 'LastLoginTime', title: '最后登陆', width: X_WIDTH.Time, align: 'center', formatter: formatShortTime },
//                    { field: 'LastLoginIp', title: '最后IP', width: X_WIDTH.Ip, align: 'center', formatter: function (v, r, k) { return v; } },
//                    { field: 'UserOnline', title: '在线', width: 50, formatter: function (v, r, k) { return X_ONLINESTATE[v]; }, align: 'center' },
//                    { field: 'DepartId', title: '部门', width: X_WIDTH.Depart, align: 'center', formatter: formatDepart },
//                    { field: 'PostId', title: '职位', width: X_WIDTH.Depart, align: 'center', formatter: formatPost }
//                ]],
//            loadFilter: function (data) {
//                data.d.Table.total = data.d.Total;
//                if (!data.d.Table.rows) data.d.Table.rows = [];
//                return data.d.Table;
//            },
//            onLoadSuccess: function (data) {
//                if (data.rows.length) {
//                    $.messager.show({ title: '操作提示', msg: '加载 ' + data.rows.length + ' 条记录成功!' });
//                }
//                else {
//                    $.messager.show({ title: '操作提示', msg: '没有数据!' });
//                }
//            }
//        });
//    }
//})('RBAC-Users_Address_List');